package org.zn.mvcbase.response;

import java.util.Map;

public class VariableDataGridConverter implements DataConverter{
	
	
	private Class<? extends ResponseMessage> gridclazz;
	
	private Map<String, DataConverter> convertermapper;
	

	public Class<?> getGridclazz() {
		return gridclazz;
	}

	public void setGridclazz(Class<? extends ResponseMessage> gridclazz) {
		this.gridclazz = gridclazz;
	}

	@SuppressWarnings("unchecked")
	public VariableDataGridConverter( Map<String, DataConverter> convertermapper ,String clazzName) throws ClassNotFoundException {
		// TODO Auto-generated constructor stub
		
		this.convertermapper=convertermapper;
		
		gridclazz=(Class<? extends ResponseMessage>) Class.forName(clazzName);

	}
	

	@Override
	public ResponseMessage converter(Metadata md, ResponseMessage rm) {
		// TODO Auto-generated method stub
		
		ResponseMessage nrm=null;
		try {
			nrm = gridclazz.newInstance();
		} catch (InstantiationException | IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
	    DataConverter dc=convertermapper.get(nrm.getMapperKey());
		dc.converter(md, nrm);
		
		return nrm;
	}

}
